package com.poem.controller;

import com.poem.dto.TypesQueryDTO;
import com.poem.dto.UserDTO;
import com.poem.dto.UsersPageQueryDTO;
import com.poem.entity.Types;
import com.poem.entity.Users;
import com.poem.result.PageResult;
import com.poem.result.Result;
import com.poem.service.UsersService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: UsersController
 * @Author: YLY
 * @Description:
 * @Date: 2025/10/24
 * @Version: 1.0
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class UsersController {

    @Resource
    private UsersService usersService;

    /**
     * 查询所有用户
     * 
     * @return
     */
    @GetMapping("/list")
    public Result<List<Users>> list() {
        log.info("查询所有用户");
        List<Users> usersList = usersService.queryAllUsers();
        return Result.success(usersList);
    }

    /**
     * 修改用户
     * 
     * @param userDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody UserDTO userDTO) {
        log.info("修改用户:{}", userDTO);
        usersService.updateUser(userDTO);
        return Result.success();
    }

    /**
     * 分页查询用户
     * 
     * @param usersPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<Users>> pageQuery(UsersPageQueryDTO usersPageQueryDTO) {
        log.info("分页查询：{}", usersPageQueryDTO);
        PageResult<Users> pageResult = usersService.pageQuery(usersPageQueryDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("删除用户:{}", ids);
        usersService.deleteBatch(ids);
        return Result.success();
    }

}
